using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;


namespace QLCHPM
{
    class XuLy
    {
        public static double tong(double x, double y)
        {
            return x + y;
        }
        public static double tru(double x, double y)
        {
            return x - y;
        }
        public static double can(double x)
        {
            if (x > 0)
            {
                return Math.Sqrt(x);
            }
            return 0;
        }
        // phep nhan
        public static double nhan(double x, double y)
        {
            return x * y;
        }
        //phep chia
        public static double chia(double x, double y)
        {
            return x / y;
        }
        public static double motphanx(double x)
        {
            return 1/x;
        }
        // giai thua

        public static double giaithua(double x)
        {
            if (x == 1)
            {
                return 1;
            }
            else
                return x * giaithua(x - 1);
        }
        //tinh sin
        public static double sin(double x, int co)
        {
            if (co == 1)
            {
                return Math.Sin((x * Math.PI) / 180);
            }
            return Math.Sin(x);
        }
        
        // tinh cos
        public static double cos(double x,int co)
        {
            if (co == 1)
            {
                return Math.Cos((x * Math.PI) / 180);
            }
            return Math.Cos(x);
        }
       //tinh so mu
        public static double xmuy(double x, double y)
        {
            return Math.Pow(x, y);
        }
        
        public static double mod(double x, double y)
        {
            return x % y;
        }
        public static double log(double x)
        {
            return Math.Log10(x);
        }
        public static double ln(double x)
        {
            return Math.Log(x, Math.E);
        }
        public static double exp(double x, double y)
        {
            return x * Math.Pow(10, y);
        }
        public static long xor(long x, long y)
        {
            long so1 = x ^ y;
            return so1;
        }
        public static double xmu3(double x)
        {
            return (x * x * x);
        }
        public static double xmu2(double x)
        {
            return (x * x);
        }
        public static string chuyendoihesodecsangbin(double x)
        {
            string so = "";
            double y;
            while (x > 0)
            {
                y = (x % 2);
                x = Math.Truncate(x / 2);

                so = y.ToString()+so;

            }
            return so;

        }
        public static string chuyendoihesodecsangoct(double x)
        {
            string so = "";
            double y;
            while (x > 0)
            {
                y = (x % 8);
                x = Math.Truncate(x / 8);

                so = y.ToString() + so;

            }
            return so;
        }
        public static string chuyendoihesodecsanghex(double x)
        {
            string so = "";
            double y; string nho = "";
            while (x > 0)
            {
                y = (x % 16);
                x = Math.Truncate(x / 16);
                if (y < 10)
                {
                    nho = y.ToString();
                }
                else
                {
                    string tam = y.ToString();
                    switch (tam)
                    {
                        case "10":
                            nho = "A"; break;
                        case "11":
                            nho = "B"; break;

                        case "12":
                            nho = "C"; break;
                        case "13":
                            nho = "D"; break;
                        case "14":
                            nho = "E"; break;
                        case "15": nho = "F"; break;
                    }
                }
                so = nho + so;
            }
            return so;
        }

        public static string chuyenhe10(string s)
        {
            double kq=0;
            int d = s.Length;
            for (int i = 0;i<d ; i++)
            {
                if (s[i].ToString() == "1")
                {
                    kq = kq + xmuy(2,d-i-1);
                }
                //kq = kq + 0;
            }
            return kq.ToString();

        }
        public static string chuyenhe8sang10(string s)
        {
            
            double kq = 0;
            int d = s.Length;
            double so = double.Parse(s); int i=0;
            while(d>0)
            {

                double tam; tam = so % 10;
                kq = kq + tam*xmuy(8, i);
                so=(so-tam)/10;
                i++; d--;
                
            }
            return kq.ToString();
        }
        public static string chuyenhe16sang10(string s)
        {
            double kq = 0; int d = s.Length;

            for (int i = 0; i < d; i++)
            {
                
                if (s[i].ToString()=="A")
                    kq = kq + 10 * xmuy(16, d - i - 1);
                if(s[i].ToString()=="B")
                    kq = kq + 11 * xmuy(16, d - i - 1); 
                if(s[i].ToString()=="C")
                    kq = kq + 12 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="D")
                        kq = kq + 13 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="E")
                        kq = kq + 14 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="F")
                        kq = kq + 15 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="1")
                        kq = kq + 1 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="2")
                        kq = kq + 2 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="3")
                        kq = kq + 3 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="4")
                        kq = kq + 4 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="5")
                        kq = kq + 5 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="6")
                        kq = kq + 6 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="7")
                        kq = kq + 7 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="8")
                        kq = kq + 8 * xmuy(16, d - i - 1); 
                    if(s[i].ToString()=="9")
                        kq = kq + 9 * xmuy(16, d - i - 1); 
                    
            }
                
                return kq.ToString();
            
            
        }
    }
}

